package com.duowan.realtime.dao.impl;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;

import com.duowan.realtime.dao.BaseSpringJdbcDao;
import com.duowan.realtime.dao.OdsRawActionLogDao;
import com.duowan.realtime.model.OdsRawActionLog;

public class OdsRawActionLogDaoImpl extends BaseSpringJdbcDao implements OdsRawActionLogDao {
	
	private static final String ODS_RAW_ACTION_LOG_COLUMNS = "dt,stime,product,iver,mid,passport,yyuid,game,game_server";
	
	@Override
	public void insertBatch(final List<OdsRawActionLog> odsRawActionLogs) {
		String sql = "INSERT INTO ods_raw_action_log("+ ODS_RAW_ACTION_LOG_COLUMNS + ")" + " values(?,?,?,?,?,?,?,?,?)";
		List<Object[]> batchArgs = new ArrayList<Object[]>();  
		for (OdsRawActionLog oal : odsRawActionLogs) {
			Object[] args = {oal.getDt(),oal.getStime(),oal.getProduct(),oal.getIver(),oal.getMid(),oal.getPassport(),oal.getYyuid(),oal.getGame(),oal.getGameServer()};
			batchArgs.add(args);
		}
		long startTime = System.currentTimeMillis();
		getSimpleJdbcTemplate().batchUpdate(sql, batchArgs);
		System.out.println((System.currentTimeMillis() - startTime)/1000);
//		getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
			
//			@Override
//			public void setValues(PreparedStatement ps, int i) throws SQLException {
//				List<Object[]> batchArgs = new ArrayList<Object[]>();  
//				for (OdsRawActionLog oal : odsRawActionLogs) {
//					Object[] args = {oal.getDt(),oal.getStime(),oal.getProduct(),oal.getIver(),oal.getPassport(),oal.getYyuid(),oal.getGame(),oal.getGameServer()};
//					batchArgs.add(args);
//				}
//				getJdbcTemplate().batchUpdate(sql, batchArgs);
//				ps.setString(1, odsRawActionLogs.get(i).getDt());
//				ps.setString(2, odsRawActionLogs.get(i).getStime ());
//				ps.setString(3, odsRawActionLogs.get(i).getProduct());
//				ps.setString(4, odsRawActionLogs.get(i).getIver());
//				ps.setString(5, odsRawActionLogs.get(i).getMid());
//				ps.setString(6, odsRawActionLogs.get(i).getPassport());
//				ps.setString(7, odsRawActionLogs.get(i).getYyuid());
//				ps.setString(8, odsRawActionLogs.get(i).getGame());
//				ps.setString(9, odsRawActionLogs.get(i).getGameServer());
//				
//			}
			
//			@Override
//			public int getBatchSize() {
//				return odsRawActionLogs.size();
//			}
//		});
	}

}
